<template>
  <div class="app-container">
    <pro-card>
      <el-form :model="queryParams" :inline="false" label-position="right" label-width="auto">
            #_query_form_#
        <el-row class="mt20">
          <el-col :span="6">
            <el-form-item>
              <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
              <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">查询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </pro-card>
    <pro-card>
      <el-row :gutter="10" class="mt-7 pull-right">
        <el-col :span="1.5">
          <el-button
              type="primary"
              icon="el-icon-plus"
              size="small"
              @click="handleShowAddDialog"
              v-hasPermi="['#_permission_#:add']"
          >新增
          </el-button>
        </el-col>
      </el-row>
      <mq-table-line title="#nameCN#" />
      <el-table v-loading="loading" element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading" :data="dataRst" max-height="1000px">
                #_table_content_#
        <el-table-column
            label="操作"
            width="120"
        >
          <template slot-scope="scope">
            <el-button size="small" type="text" icon="el-icon-edit-outline" v-hasPermi="['#_permission_#:update']" @click="showUpdateDialog(scope.row)">修改</el-button>
            <el-button size="small" type="text" icon="el-icon-delete" v-hasPermi="['#_permission_#:delete']" @click="showConfirmDeleteDialog(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
          v-show="dataRstTotal>0"
          :total="dataRstTotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
      />
    </pro-card>
    <!-- 修改 -->
    <el-dialog title="修改" :visible.sync="showUpdateDialogFlag" v-loading="loadingUpdate" element-loading-text="拼命加载中"
               element-loading-spinner="el-icon-loading" width="500px"
               append-to-body>
      <el-form :model="updateForm" :inline="false" label-width="80px">
        #_update_form_#
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleUpdateButton" size="small" icon="el-icon-check">确 定</el-button>
        <el-button @click="cancelShowUpdateDialog" size="small" icon="el-icon-close">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 新增 -->
    <el-dialog title="新增" :visible.sync="showAddDialogFlag" v-loading="loadingAdd" element-loading-text="拼命加载中"
               element-loading-spinner="el-icon-loading" width="500px"
               append-to-body>
      <el-form :model="addForm" :inline="false" label-width="80px">
       #_add_form_#
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSubmitAddButton" size="small" icon="el-icon-check">确 定</el-button>
        <el-button @click="cancelShowAddDialog" size="small" icon="el-icon-close">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import ProCard from "@/components/ProCard";
import MqTableLine from "@/views/components/MqTableLine";
import {formatBoolean2MsgBase} from "@/api/common_select";
import {
  delete#nameEN#,
  handle#nameEN#AddButton,
  handle#nameEN#UpdateButton,
  list#nameEN#DataByPage
} from "@/api/amazon/apiRoute";
export default {
  name: "#nameEN#",
  components: {MqTableLine, ProCard},
  data() {
    return {
      formatStatus2Msg: function (row, column, cellValue) {
        return formatBoolean2MsgBase(row,column,cellValue)
      },
     // 更新Form
      updateForm:{},
      //
      showUpdateDialogFlag:false,
      // 遮罩层
      loading: false,
      loadingUpdate: false,
      loadingAdd: false,
      // 用户表格数据
      dataRst: [],
      // 总条数
      dataRstTotal: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },

      // 新增窗口
      showAddDialogFlag: false,
      // 新增Form
      addForm: {
      },
    };
  },
  watch: {
  },
  created() {
    this.getList();
  },
  methods: {

    //显示新增窗口
    handleShowAddDialog() {
      this.showAddDialogFlag = true;
    },
    //取消显示新增窗口
    cancelShowAddDialog() {
      this.showAddDialogFlag = false;
    },
    // 提交新增按钮
    handleSubmitAddButton() {
      this.loadingAdd = true;
      handle#nameEN#AddButton(this.addForm).then(resp =>{
        if(resp.success === true) {
          this.getList();
          this.$modal.msgSuccess("新增成功");
          this.cancelShowAddDialog();
        }
      });
      this.loadingAdd = false;
    },

    // 取消显示更新
    cancelShowUpdateDialog() {
      this.showUpdateDialogFlag = false;
    },
    // 显示更新
    showUpdateDialog(row) {
      this.updateForm = row;
      this.showUpdateDialogFlag = true;
    },
    handleUpdateButton(query) {
      this.loadingUpdate = true;
      handle#nameEN#UpdateButton(this.updateForm).then(resp =>{
        if(resp.success === true) {
          this.getList();
          this.cancelShowUpdateDialog();
        }
      });
      this.loadingUpdate = false;
    },

    /** 分页查询 */
    getList() {
      this.loading = true;
      list#nameEN#DataByPage(this.queryParams).then(response => {
            this.dataRst = response.rows;
            this.dataRstTotal = response.total;
            this.loading = false;
          }
      ).catch(exp =>{
        this.loading = false;
      });
      this.loading = false;
    },

    // 删除
    showConfirmDeleteDialog(row) {
      let param = {
        id: row.id
      }
      this.$modal.confirm('确认要删除id为' + row.id +' 的数据吗？').then(function() {
        return delete#nameEN#(param).then(resp =>{
        });
      }).then(() => {
        this.$modal.msgSuccess("删除成功");
        this.getList();
      }).catch(function() {
      });
    },

    //----------- 公共的搜索框 -----------
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.queryParams = {};
    },
    //----------- 公共的搜索框 -----------
  }
};
</script>